package com.leetcode.LC;

import java.util.ArrayList;
import java.util.List;

public class LC696 {
    public int countBinarySubstrings(String s) {

        s=s+"2";
        List<Integer> counts = new ArrayList<Integer>();
        int num=1;
        for (int i = 0; i < s.length()-1; i++) {
            if (s.charAt(i)==s.charAt(i+1)){
                num++;
            }else {
                counts.add(num);
                num=1;
            }
        }

        int ans = 0;
        for (int i = 1; i < counts.size(); ++i) {
            ans += Math.min(counts.get(i), counts.get(i - 1));
        }
        return ans;

    }

    public static void main(String[] args) {
        System.out.println(new LC696().countBinarySubstrings("00110011"));
    }
}
